{% extends 'base_auth.html' %}

{% block title %}登录 - EasyTesting{% endblock %}

{% block content %}
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-6 col-lg-5">
                <div class="card shadow-sm border-0 mt-5">
                    <div class="card-body p-5">
                        <div class="text-center mb-4">
                            <h1 class="h3 mb-3 fw-normal">EasyTesting</h1>
                            <p class="text-muted">登录您的账户</p>
                        </div>

                        {% if form.errors %}
                            <div class="alert alert-danger">
                                <i class="bi bi-exclamation-triangle-fill me-2"></i>
                                用户名或密码不正确，请重试。
                            </div>
                        {% endif %}

                        {% if messages %}
                            {% for message in messages %}
                                <div class="alert alert-{{ message.tags }}">
                                    {{ message }}
                                </div>
                            {% endfor %}
                        {% endif %}

                        <form method="post" action="{% url 'login' %}">
                            {% csrf_token %}
                            <div class="mb-3">
                                <label for="id_username" class="form-label">用户名</label>
                                <div class="input-group">
                                    <span class="input-group-text"><i class="bi bi-person"></i></span>
                                    <input type="text" name="username" id="id_username" class="form-control"
                                           placeholder="输入用户名" required autofocus>
                                </div>
                            </div>

                            <div class="mb-3">
                                <label for="id_password" class="form-label">密码</label>
                                <div class="input-group">
                                    <span class="input-group-text"><i class="bi bi-lock"></i></span>
                                    <input type="password" name="password" id="id_password" class="form-control"
                                           placeholder="输入密码" required>
                                </div>
                            </div>

                            <div class="d-flex justify-content-between align-items-center mb-3">
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" name="remember" id="remember">
                                    <label class="form-check-label" for="remember">
                                        记住我
                                    </label>
                                </div>
                                <a href="{% url 'password_reset' %}" class="text-decoration-none">忘记密码?</a>
                            </div>

                            <input type="hidden" name="next" value="{{ next }}">

                            <button class="w-100 btn btn-primary" type="submit">
                                <i class="bi bi-box-arrow-in-right me-2"></i>登录
                            </button>
                            </a>
                            <div class="text-center mt-4">
                                <p>还没有账户? <a href="{% url 'register' %}" class="text-decoration-none">立即注册</a>
                                </p>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
